﻿
//----------------------------------------------------------------------
// <copyright file="EntityOperator.cs" company="NTT DATA BEEN (China)">
// Copyright (c)2012 NTT DATA BEEN (China) Information Technology Co.,Ltd.
// </copyright>
// <author> lidawei </author>
// <summary>
// システム名称　　：
// モジュールＩＤ　：
// モジュール名称　：
// 機能概要　　　　：EntityOperator类 
// 改訂履歴　　　　：
// 2012-08-01 新規 lidawei    Been0001   
// </summary>
//---------------------------------------------------------------------- 

namespace Ntt.NttData.Been.Management.SolutionA.Sync.Operator.Model
{
    using System;
    using System.Collections.Generic;
    using BLL;


    public class EntityOperator:IComparer<EntityOperator>
    {
        public string OperatorNo { get; set; }
        public string OperatorPass { get; set; }
        public string  OperatorNameKana{ get; set; }
        public string  OperatorName{ get; set; }
        public int  OperatorGender{ get; set; }
        public int ERankId { get; set; }
        public DateTime UpdateTime { get; set; }


        public ESyncAction GetSyncAction(EntityOperator other)
        {
           ESyncAction action = ESyncAction.Ignore;

           if (other == null)
           {
               action = ESyncAction.Insert;
           }
           else
           {
               int compareResult = string.Compare(OperatorNo, other.OperatorNo, StringComparison.OrdinalIgnoreCase);
               if (compareResult == 0)
               {
                   //用值来判断
                  // compareResult = Compare(this, other);

                   //用时间判断
                   compareResult = DateTime.Compare(UpdateTime, other.UpdateTime);
                   
                   //此处的时间 可能永远对不上 没有一样的时候
                   if (compareResult != 0)
                   {
                       action = ESyncAction.Update;
                   }                     
                   
               }
               else if ( compareResult < 0 )
               {
                   action = ESyncAction.Insert;
               }
               else if ( compareResult > 0 )
               {
                   action = ESyncAction.Delete;
               }
            }
            return action;
        }


        /// <summary>
        /// Compares the specified x.
        /// 帐号密码不区分大小写
        /// </summary>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        /// <returns></returns>
        public int Compare(EntityOperator x, EntityOperator y)
        {
            bool result = (string.Compare(x.OperatorNo, y.OperatorNo, StringComparison.OrdinalIgnoreCase) == 0 &&
                           string.Compare(x.OperatorName, y.OperatorName, StringComparison.OrdinalIgnoreCase) == 0 &&
                           string.Compare(x.OperatorNameKana, y.OperatorNameKana, StringComparison.OrdinalIgnoreCase) == 0 &&
                           string.Compare(x.OperatorPass, y.OperatorPass, StringComparison.OrdinalIgnoreCase) == 0 &&
                           x.OperatorGender == y.OperatorGender &&
                           x.ERankId == y.ERankId);


            if (result)
                return 0;

            return -1;
        }
    }
}
